// user_super.go 实现了超级用户查询药店，以及药店人员 的功能
package super

import (
	"Project/global"
	"Project/model/common/response"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"strconv"
)

type DrugShopApi struct{}

//GetAllDrugShop 查询所有的药店
func (u *DrugShopApi) GetAllDrugShop(c *gin.Context) {
	// 查找所有的药店
	list, err := shopService.DrugShopList()
	if err != nil {
		response.Fail(c)
		return
	}
	// 返回结果
	response.OkWithData(list, c)
}

// GetDrugUserList 获取药店用户列表
func (u *DrugShopApi) GetDrugUserList(c *gin.Context) {
	// 获取药店ID，转为int64
	shopId := c.Param("shop_id")
	global.GVA_LOG.Debug("c.Param:", zap.Any("shop_id", shopId))
	if shopId == "" {
		response.FailWithMessage("参数错误", c)
		return
	}
	shopIdInt, err2 := strconv.ParseInt(shopId, 10, 64)
	if err2 != nil {
		return
	}
	// 根据药店id获取该药店所有销售人员
	list, err := userSaleService.GetAllUserSaleByShopId(shopIdInt)
	if err != nil {
		response.Fail(c)
		return
	}
	response.OkWithData(list, c)
}
